//
//  CommonProtocol.swift
//  Pan
//
//  Created by susu on 2020/12/21.
//  Copyright © 2020 ios. All rights reserved.
//

import Foundation
import UIKit
import MXCommonModule

protocol ScrollviewAdjustInset: UIViewController {
    func adjustInset()
}
protocol CustomNavgationBar: UIViewController {
    func createCustomBackgroundView()
    func creatClearNavigationBar(title: String)
}
extension ScrollviewAdjustInset{
    func adjustInset() {
        if #available(iOS 11.0, *) {
            UIScrollView.appearance().contentInsetAdjustmentBehavior = UIScrollView.ContentInsetAdjustmentBehavior.never
        }else{
            self.automaticallyAdjustsScrollViewInsets = false
        }
    }
}

extension CustomNavgationBar{
    
    func backAction(){
        self.navigationController?.popViewController()
    }
    
    func createCustomBackgroundView(){
        let backImgeView = UIImageView(image: imageWithName("img_common_background"))
        self.view.addSubview(backImgeView)
        backImgeView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    func creatClearNavigationBar(title: String){
        self.navigationController?.navigationBar.barStyle = .default
        setNeedsStatusBarAppearanceUpdate()
        let backColor = UIColor.clear
        let imageIcon = imageWithName("icon_xgl_back_white")
       
        let view = UIView().then { make in
            make.backgroundColor = backColor
        }
        let backItem = MXCustomButton().then { make in
            make.setImage(imageIcon, for: .normal)
            make.buttonSelectAction { [weak self] in
                guard let `self` = self else { return }
                self.backAction()
            }
        }
        let titleView = UILabel().then { make in
            make.textColor = UIColor.white
            make.font = UIFont.pingfangSC_Regular(fontSize: 18.0)
            make.text = title
        }
        view.addSubview(backItem)
        view.addSubview(titleView)
        self.view.addSubview(view)
        backItem.snp.makeConstraints { make in
            make.left.equalTo(5.0)
            make.width.height.equalTo(50.0)
            make.bottom.equalTo(-3.0)
        }
        titleView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.centerY.equalTo(backItem)
        }
        view.snp.makeConstraints { make in
            make.centerX.top.equalToSuperview()
            make.width.equalTo(ScreenWidth)
            make.height.equalTo(PanNavibarH)
        }

    }
}
